import { createApp } from "vue";
import App from "./App.vue";
import store from "./store";

import './assets/css/common.css';
import './assets/css/emoji/emoji.css';
import './assets/css/emoji/index.css';

// element-ui组件
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import ElIcons from './components/elicons';
// components
import components from './components'; // 全局组件注册

// global
import http from "./global/http";
import config from "./global/config";
import storage from "./global/storage";
import utils from './global/utils';

const app = createApp(App);
const { config: { globalProperties: global } } = app;
const { filters: { formatTime, systemMenuTypeToStr, systemUserRole, unescape }, validate, msgBox, msg, common } = utils;

// 全局变量
global.$http = http; // http请求
global.$config = config; // 本地配置
global.$storage = storage; // 本地储存
global.$utils = common; // 公共函数
global.$formatTime = formatTime; // 时间过滤
global.$systemMenuTypeToStr = systemMenuTypeToStr; // 菜单分类过滤
global.$roles = systemUserRole; // 角色
global.$unescape = unescape; // 转义符号
global.$validate = validate; // 正则验证
global.$msgBox = msgBox; // 消息弹出框
global.$msg = msg; // 消息提示

// 表单action统一宽度
global.$minActionWidth = '100'; // 一般用于1标签
global.$defaultActionWidth = '200'; // 一般用于2个标签
global.$maxActionWidth = '320'; // 一般用于3个标签

const init = async () => {
    const module = await import('./router');
    const router = await module.default;

    // 验证页面按钮是否有权限
    global.isAuth = function (code = '') {
        const authArr = router.currentRoute.value.meta.auth;
        if (code != '') {
            if (authArr.indexOf(code) >= 0) {
                return true;
            } else {
                return false;
            }
        }
    };

    app
        .use(router)
        .use(store)
        .use(ElementPlus, { size: 'default', zIndex: 3000 })
        .use(ElIcons)
        .use(components)
        .mount("#app");
};

init();

